﻿package ;

import flash.Lib;

import api.DAO;

/**
 * http://vkontakte.ru/app1690549
 * @author Артём Григорьев
 */

class Main 
{
	private static var apiId:		Int 		= 1690549;
	private static var apiSecret:	String 		= "aSQDlpnsAu";
	private static var uid:			Int			= 0;
	private static var apiURL:		String		= "http://api.vkontakte.ru/api.php";
	
	private static var dao:			DAO;
	
	private static function onComplete(userInfos: Array < UserInfo >) : Void 
	{
		var info: UserInfo = userInfos[0];
		trace("id: " + info.uid);
		trace("имя: " + info.firstName);
		trace("фамилия: " + info.lastName);
		trace("пол: " + info.sex);
		trace("д/р: " + info.birthDate);
		trace("город: " + info.city);
		trace("страна: " + info.country);
		trace("часовой пояс: " + info.timezone);
		trace("фото: " + info.photo);
		trace("фото-2: " + info.photoMedium);
		trace("фото-3: " + info.photoBig);
	}
	
	private static function onCompleteF2(userInfos: Array < UserInfo >) : Void 
	{
		trace("Друзья:");
		for (info in userInfos) {
			trace(info.firstName + " " + info.lastName);
		}
	}
	
	private static function onCompleteF(users: Array <Int>) : Void
	{
		dao.getProfiles(users, null, ["first_name", "second_name"], onCompleteF2, onError);
	}
	

	
	private static function onError(s: String) : Void 
	{
		trace(s);
	}
	
	private static function run()
	{
		dao	= new DAO(apiId, apiSecret, uid, false);
		dao.getProfiles([uid], null, ["uid", "first_name", "second_name", "sex", "bdate", "city", "country", "timezone", "photo", "photo_medium", "photo_big"], onComplete, onError);
		dao.getFriends(onCompleteF, onError);
	}
	
	static function main() 
	{
		var params:Dynamic<String> = flash.Lib.current.loaderInfo.parameters;
		if (params.viewer_id == null) {
			trace("No viewer_id!");
		} else {
			uid = Std.parseInt( params.viewer_id );
			run();
		}
	}
	
}